#include "head.h"


int makeWorker(int wokerNum,workerData_t* workArr){
    pid_t pid;
    for(int i=0;i<wokerNum;i++){
        int fds[2];
        bzero(fds,sizeof(fds));
        socketpair(AF_LOCAL,SOCK_STREAM,0,fds);
        pid=fork();
        if(pid==0){
            while(1){
                close(fds[0]);  
                while(1){
                    int netfd;
                    int flag;
                    // recvfd(fds[1],&netfd); //添加flag标记 代码要改
                    recvfd(fds[1],&flag,&netfd);
                    if(flag==1){
                        printf("I am going to exit!\n");
                        exit(0);
                    }
                    printf("netfd=%d\n",netfd);
                    
                    /*开始执行业务*/
                    //执行下载任务
                    transFile(netfd);
                    /*业务完成*/

                    close(netfd);
                    pid_t pid=getpid();
                    send(fds[1],&pid,sizeof(pid),0);
                }
            }//子进程无法离开死循环，无法进行下面操作。
        }
        close(fds[1]);
        workArr[i].pid=pid;
        workArr[i].status=FREE;
        workArr[i].pipefd=fds[0];
        printf("i=%d,pid=%d,child_pid=%d\n",i,getpid(),pid);
    }

    return 0;
}